package com.adobe.apprise.commands
{
	import com.adobe.apprise.database.Database;
	import com.adobe.apprise.database.DatabaseEvent;
	import com.adobe.apprise.database.DatabaseResponder;
	import com.adobe.apprise.events.AggregateEvent;
	import com.adobe.apprise.model.ModelLocator;
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	public class RefreshAllCommand implements ICommand
	{
		public function execute(ce:CairngormEvent):void
		{
			var db:Database = ModelLocator.getInstance().db;
			var responder:DatabaseResponder = new DatabaseResponder();
			responder.addEventListener(DatabaseEvent.RESULT_EVENT,
				function(e:DatabaseEvent):void
				{
					var urls:Array = new Array();
					for each (var o:Object in e.data)
					{
						urls.push(o.feed_url);
					}
					if (urls.length > 0)
					{
						var ae:AggregateEvent = new AggregateEvent();
						ae.feeds = urls;
						ae.dispatch();
					}
				});
			db.getFeedUrls(responder);
		}
	}
}
